import { ProtoObject } from "../../Object/ProtoObject";
import { ISingleton } from "../../Singleton/Singleton";

export class ConfigSingleton<T extends ConfigSingleton<T>> extends ProtoObject implements ISingleton {

    private _isDisposed: boolean;

    public static get Instance(): ISingleton {
        return null;
    }

    protected set Instance(value: ISingleton) {
        console.log(`${this.constructor.name} set instance ${value}`);
    }

    Register(): void {
        if (ConfigSingleton.Instance != null) {
            throw new Error(`config singleton register twice! ${this.constructor.name}`);
        }
        this.Instance = this;
    }

    Destroy(): void {
        if (this._isDisposed) {
            return;
        }
        this._isDisposed = false;

        let t = ConfigSingleton.Instance;
        this.Instance = null;
        t.Dispose();
    }

    IsDisposed(): boolean {
        return this._isDisposed;
    }

    Dispose(): void {

    }

    public override AfterEndInit() {

    }

}